using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

public class LuaAssetCollect : AssetCollection
{
    public override string fileExtensions
    {
        get
        {
            return "t:TextAsset";
        }
    }

    public LuaAssetCollect(string findPath)
    {
        
        this.findPath = findPath;
    }

    public override void CollectAsset()
    {
        var allAssets = AssetDatabase.FindAssets(fileExtensions,new string[] { $"Assets/{this.findPath}" });
        builds = new List<AssetBundleBuild>();
        int progress = 0;
        int max = allAssets.Length;
        EditorUtility.DisplayProgressBar("Collect Progress Bar", "collect bundle asset progress", (float)(progress * 1f / max));


        foreach (var guid in allAssets)
        {
            Debug.LogError(AssetDatabase.GUIDToAssetPath(guid));
            var path = AssetDatabase.GUIDToAssetPath(guid);
            
            AssetBundleBuild build = new AssetBundleBuild();
            build.assetBundleName = path;
            build.assetNames = new string[]
            {
                AssetDatabase.GUIDToAssetPath(guid)
            };
            builds.Add(build);
            progress++;
            EditorUtility.DisplayProgressBar("Collect Progress Bar", "collect bundle asset progress", (float)(progress * 1f / max));
        }

        EditorUtility.ClearProgressBar();
        base.CollectAsset();
    }
}
